//
//  MyCell.m
//  UI13-段子
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MyCell.h"
#import "UIImageView+WebCache.h"
#import "GetHightTools.h"

@interface MyCell ()
@property (nonatomic,retain)UILabel *lable;
@property (nonatomic,retain)UIImageView *pic;

@end

@implementation MyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.lable = [[UILabel alloc]init];
        [self.contentView addSubview:self.lable];
        self.lable.numberOfLines = 0;
        [_lable release];
        self.pic = [[UIImageView alloc]init];
        [self.contentView addSubview:self.pic];
        [_pic release];
    }
    return self;
}

-(void)layoutSubviews{
    CGFloat height = [GetHightTools getHeight:self.model.digest width:414 font:self.lable.font];
    self.lable.frame = CGRectMake(0, 0, self.contentView.frame.size.width, height);
    self.lable.backgroundColor = [UIColor grayColor];
//    UIImage  *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.model.img]]];  //这个也可以但是同步请求会卡顿
    
    CGFloat imageWidth = [self.model.pixel substringToIndex:3].floatValue;
    CGFloat imageHeight =  [self.model.pixel substringFromIndex:4].floatValue;
    CGFloat screenHeight = 414 * imageHeight / imageWidth;
    self.pic.frame =  CGRectMake(0, height, self.contentView.frame.size.width, screenHeight);
    self.pic.backgroundColor = [UIColor orangeColor];
}

- (void)setModel:(Model *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    self.lable.text = model.digest;
    [self.pic sd_setImageWithURL:[NSURL URLWithString:model.img]];
    
}




























@end
